<%@ include file ="/common/ini.jsp"%>
<%@ include file ="/common/_log4j.jsp"%>
<%@ include file = "/common/_ApplicationContext_init.jsp"%> 
<%
    OperatingLogManager operatingLogManager = (OperatingLogManager)applicationContext.getBean("operatingLogManager");
    OperatingLog ol = (OperatingLog)operatingLogManager.get(request.getParameter("id"));
%>
<html>
<head>
<title>操作日志</title>
</head>
<%@ include file ="/css/detailcss.jsp"%>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
<div width="100%" align="center">
<table width="98%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td> 
      <div align="center"><b><font color="#003399"><br>
        <font size="4" color="000000">操作日志</font></font></b><br>
        <br>
      </div>
      <table width="100%" border="0" cellspacing="1" cellpadding="0" bgcolor="#c2c2c2">
        <tr> 
          <td height="25" bgcolor="e9e9e9" width="15%"> 
            <div align="right"><b><font color="000000" size="2">模 块&nbsp;&nbsp;</font></b></div>
          </td>
          <td height="25" width="30%" bgcolor="#FFFFFF"> 
            <div align="left">&nbsp;&nbsp;<font size="2"><%= ol.getModule()%></font></div>
          </td>
          <td height="25" bgcolor="e9e9e9" width="17%"> 
            <div align="right"><b><font color="000000" size="2">实 体&nbsp;&nbsp;</font></b></div>
          </td>
          <td height="25" width="38%" bgcolor="#FFFFFF"> 
            <div align="left">&nbsp;&nbsp;<font size="2"><%= ol.getModel()%></font></div>
          </td>
        </tr>
        <tr> 
          <td height="25" bgcolor="e9e9e9" width="15%"> 
            <div align="right"><b><font color="000000" size="2">操 作&nbsp;&nbsp;</font></b></div>
          </td>
          <td height="25" width="30%" bgcolor="#FFFFFF"> 
            <div align="left">&nbsp;&nbsp;<font size="2"><%= ol.getService()%></font></div>
          </td>
          <td height="25" bgcolor="e9e9e9" width="17%"> 
            <div align="right"><b><font color="000000" size="2">结 果&nbsp;&nbsp;</font></b></div>
          </td>
          <td height="25" width="38%" bgcolor="#FFFFFF"> 
            <div align="left">&nbsp;&nbsp;<font size="2"><%= ol.getResult()%></font></div>
          </td>
        </tr>
        <tr> 
          <td height="25" bgcolor="e9e9e9" width="15%"> 
            <div align="right"><b><font color="000000" size="2">操作人&nbsp;&nbsp;</font></b></div>
          </td>
          <td height="25" bgcolor="#FFFFFF" width="30%"><div align="left">&nbsp;&nbsp;<font size="2"><%= ol.getOperatorName()%></font></div></td>
          <td height="25" bgcolor="e9e9e9" width="17%"> 
            <div align="right"><b><font color="000000" size="2">时 间&nbsp;&nbsp;</font></b></div>
          </td>
          <td height="25" bgcolor="#FFFFFF" width="30%"><div align="left">&nbsp;&nbsp;<font size="2"><%= ol.getFormatedOperatingTime("yyyy-MM-dd HH:mm:ss")%></font></div></td>
        </tr>
        <tr> 
          <td height="30" colspan="4" bgcolor="e9e9e9"> 
            <TABLE width="100%">
                <TR>
                    <TD align="center"> 
                        <font size="2" color="000000"><b>原记录</b></font>
                    </TD>
                    <TD align="center"> 
                        <font size="2" color="000000"><b>操作记录</b></font>
                    </TD>
                </TR>
            </TABLE>
          </td>
        </tr>
<%
    logger.debug("开始解析detail的xml" + ol.getDetail());
    Element root ;
    InputStream is = new StringBufferInputStream(new String(ol.getDetail().getBytes("utf-8"),"ISO8859_1"));
    Element newEle,oldEle;
    List newModelEles,oldModelEles;
    try
    {
        SAXBuilder sb = new SAXBuilder();
        Document doc = sb.build(is);
        root = doc.getRootElement(); 
        logger.debug(doc.getRootElement().getChildren());
        newEle = root.getChild("new");
        oldEle = root.getChild("old");
        // new、old modelEle
        newModelEles = this.getChildren(newEle,"model");
        oldModelEles = this.getChildren(oldEle,"model");
    }
    finally
    {
        is.close();
    }
    int modelCount = this.getMaxSize(newModelEles,oldModelEles);
    for(int i = 0; i < modelCount; i ++)
    {
        String tr = "F8F8F8";
        if(i%2 != 0)
            tr = "F7FAFE";
        Element oldModel = this.getEle(oldModelEles,i);
        Element newModel = this.getEle(newModelEles,i);
        //      打印new model fields
        List oldFields = this.getChildren(oldModel,"field");
        List newFields = this.getChildren(newModel,"field");
        int fieldCount = this.getMaxSize(oldFields,newFields);
        // 打印old
        for(int j = 0 ; j < fieldCount; j ++)
        {
            // old field
            String oldKey = ""; 
            String oldValue = "";
            Element fieldEle = this.getEle(oldFields,j);
            if(fieldEle != null)
            {
                oldKey = fieldEle.getAttribute("id").getValue();
                oldValue = fieldEle.getText();
            }
%>
    <tr bgcolor="<%= tr%>">
          <td height="25" width="15%" bgcolor="e9e9e9"> 
            <div align="right"><font color="000000" size="2"><B><%= oldKey%></B></font>&nbsp;&nbsp;</div>
          </td>
          <td height="25" width="30%"> 
            <div align="left">&nbsp;&nbsp;<%= oldValue%></div>
          </td>
<%
            // new field
            String newKey = ""; 
            String newValue = "";
            fieldEle = this.getEle(newFields,j);
            if(fieldEle != null)
            {
                newKey = fieldEle.getAttribute("id").getValue();
                newValue = fieldEle.getText();
            }
%>
          <td height="25" width="15%" bgcolor="e9e9e9"> 
            <div align="right"><font color="000000" size="2"><B><%= newKey%></B></font>&nbsp;&nbsp;</div>
          </td>
          <td height="25" width="30%"> 
            <div align="left">&nbsp;&nbsp;<%= newValue%></div>
          </td>
    </tr>
<%
        }// for ( int j

    } // for(int i = 0; i < modelCount; i ++)   
%>
        
      </table>
    </td>
  </tr>
</table>
</div>
<br>
<br>
<div width="100%" align="center"><input type="button" value="关闭" class="input" onclick="window.close();"></div>
</body>
</html>
<%! 
    private Element getEle(List eles,int index)
    {
        if(index < eles.size())
            return (Element)eles.get(index);
        else
            return null;
    }
%>
<%!
    private List getChildren(Element ele,String key)
    {
        if(ele == null)
            return new Vector();
        else
            return ele.getChildren(key);
    }
%>
<%!
    private int getMaxEleNum(Element ele1,String key1,Element ele2,String key2)
    {
        if(ele1 == null)
        {
            if(ele2 == null)
                return 0;
            else
                return ele2.getChildren(key2).size();
        }
        else
        {
            if(ele2 == null)
            {
                return ele1.getChildren(key1).size();
            }
            else
            {
                if(ele1.getChildren(key1).size() > ele2.getChildren(key2).size())
                    return ele1.getChildren(key1).size();
                else
                    return ele2.getChildren(key2).size();
            }
        }
    }
%>
<%!
    private int getMaxSize(List ls1,List ls2)
    {
        if(ls1.size() > ls2.size())
        {
            return ls1.size();
        }
        else
        {
            return ls2.size();
        }
    }
%>
